﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.IO;


    class RemoveWords
    {
        static void Main(string[] args)
        {
            try
            {
                string regex = @"\b(" + string.Join(" ", File.ReadAllLines("words.txt")) + @")\b";
                using (StreamReader file = new StreamReader("file.txt"))
                {
                    using (StreamWriter newFile = new StreamWriter("newFile.txt"))
                    {
                        for (string line; (line = file.ReadLine()) != null; )
                        {
                            newFile.WriteLine(Regex.Replace(line, regex, string.Empty));
                        }
                    }
                }

            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("The file not found!");
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine("The directory not found!");
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }

